import { h, render } from 'vue'
import confirmComponent from './index.vue'
export const confirm = (title, description, cancelButton, confirmButton) => {
    return new Promise((resolve, reject) => {
        if (title && !description) {
            description = title
            title = ''
        }
        // 取消事件
        const cancelEvent = () => {
            reject()
        }
        // 确定事件
        const confirmEvent = () => {
            resolve()
        }

        // 关闭回调
        const closedCallback = () => {
            render(null, document.body)
        }
        // h函数接收三个，第一个组件 第二个props第三个children
        const vnode = h(confirmComponent, {
            title,
            description,
            cancelButton,
            confirmButton,
            cancelEvent,
            confirmEvent,
            closedCallback
        })
        // 调用render函数渲染
        render(vnode, document.body)
    })

}